def add_num(a, b):
    return abs(a) + abs(b)


print(add_num(-1, 2))


# 函数作为参数传入，为高阶函数
def high_func(a, b, f):
    return f(a) + f(b)


print(high_func(-10, -5, abs))

# 内置的函数有map(func,list),reduce(func,list),filter()

list1 = [0, 1, 2, 3]


def func(a):
    return a ** 2


print(map(func, list1))
print(list(map(func, list1)))

import functools

list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


def func1(a, b):
    return a + b


result1 = functools.reduce(func1, list2)
print(result1)


def func_filtertest(x):
    return x % 2 == 0


result2 = filter(func_filtertest, list2)
print(list(result2))
